<?php
/* @var $this SurveyUserController */
/* @var $model SurveyUser */
/* @var $form CActiveForm */
Yii::app()->clientScript->registerScript('admin', "
	$(document).ready(function(){
		choujiang();
	})
");

$activity_code = $_GET['activity_code'];

?>
<!--ajax代码-->
<script type="text/javascript">
	function choujiang(){
		/*
		$('#SurveyUser_activety_code').append('<option value=0>'+'<?php echo Yii::t('base','Please choose');?>'+'</option>');
		$('#SurveyUser_activety_code option[value=0] ').attr('selected',true);
		
		$('#provide_gift_number').append('<option value=0>'+'<?php echo Yii::t('base','Please choose Title');?>'+'</option>');
		$('#provide_gift_number option[value=0] ').attr('selected',true);
		*/
		var code = $('#SurveyUser_activety_code').val();
		if(code != 0){
			//活动管理自动抽奖
			$.get("<?php echo Yii::app()->createUrl('surveyUser/GiftNumber'); ?>", //调用控制器action获取内容
		            { code: code},
		            function(data){
		                var options = '';
		                if(data == ""){
		                	 options += "<option value='0'><?php echo Yii::t('base','Please choose Title');?> </option>";
		                }else{
		                	 options += "<option value=" + data+ ">" + data + "</option>"; //遍历赋值
		                }
		                $("#provide_gift_number").html(options); // 数据插入到地区下拉表！
		            });
		}
		//用户调查,自动抽奖
		$('#SurveyUser_activety_code').change(function(){
			var code = $('#SurveyUser_activety_code').val();
			$.get("<?php echo Yii::app()->createUrl('surveyUser/GiftNumber'); ?>", //调用控制器action获取内容
            { code: code},
            function(data){
                var options = '';
                if(data == ""){
                	 options += "<option value='0'><?php echo Yii::t('base','Please choose Title');?> </option>";
                }else{
                	 options += "<option value=" + data+ ">" + data + "</option>"; //遍历赋值
                }
                $("#provide_gift_number").html(options); // 数据插入到地区下拉表！
            });
		});
	}
</script>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'survey-user-form',
	'enableAjaxValidation'=>false,
)); 
?>

	<p class="note"><?php echo Yii::t('base','Fields with <span class="required">*</span> are required.');?></p>

	<?php
		$errorId = $_GET['errorId'];
		if($errorId == 1){?>
			<p class="red"><?php echo Yii::t('base','Please Enty Draw Prize Qty');?></p>
	<?php	}elseif($errorId == 2){?>
			<p class="red"><?php echo Yii::t('base','Under the current sweepstakes without user or the user does not fill in mobile number');?></p>
	<?php }?>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'activety_code'); ?>
		<?php echo $form->dropDownList($model,'activety_code',SurveyUser::model()->getActivetyCodeTitle(),array('options' => array($activity_code=>array('selected'=>true)))); ?>
		<?php echo $form->error($model,'activety_code'); ?>
	</div>

	<div class="row">
		<label for="SurveyUser_activety_code"><?php echo Yii::t('base','Provide Gift Number');?> <span class="required">*</span></label>
		
		<select name="provide_gift_number" id="provide_gift_number" ></select>
	</div>
	
	<div class="row">
		<label for="SurveyUser_activety_code"><?php echo Yii::t('base','Draw Prize Qty');?> <span class="required">*</span></label>
		
		<input type="text" name="lottery_numbers" id="lottery_numbers"/>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('base','Lucky draw') : Yii::t('base','Save')); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->